home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5776 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.1 KB  |  77 lines

  1. Path: ix.netcom.com!netnews
  2. From: spdcool@ix.netcom.com(SPD)
  3. Newsgroups: comp.lang.c
  4. Subject: I need help on putting 2 strings together into 1(concatenate)
  5. Date: 20 Feb 1996 15:57:31 GMT
  6. Organization: Netcom
  7. Message-ID: <4gcr1b$ft3@cloner4.netcom.com>
  8. NNTP-Posting-Host: ix-nyc16-01.ix.netcom.com
  9. X-NETCOM-Date: Tue Feb 20  7:57:32 AM PST 1996
  10.  
  11. Hi, 
  12.  
  13.   I figured out my earlier problem.  Thanks to all that helped.  Now I
  14. have another problem.  First take a look at a short version of my code:
  15. To conserve time, I didn't use any user define constants 
  16.  
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <time.h>
  21. struct data {
  22.     char *full_name;
  23.     int age;
  24.     float salary;
  25.  };
  26.  
  27. struct name  {
  28.    char *first1, *last1;
  29.   };
  30.  
  31.  
  32. int main(void)
  33.   struct name fname[3], lname[3];
  34.   struct data secret[5];
  35.   int i, ran;
  36.  
  37.   fname[o].first1 = "Joe";
  38.   fname[1].first1 = "Michael";
  39.   fname[2].first1 = "Bruce";
  40.   lname[0].last1 = "Jordan";
  41.   lname[1].last1 = "Willis";
  42.   lname[2].last1 = "Jackson";
  43.  
  44.   randomize()
  45.   for (i = 0; i < 5; ++i)  {
  46.    e = random(3);
  47.    secret[i].full_name = fname[e].first1;/* the trouble some part begin
  48.    e = random(3);
  49.    strcat(secret[i].full_name," ");
  50.    strcat(secret[i].full_name,lname[e].last1);  /*trouble ends here*/
  51.     "
  52.      "
  53.      "  /* the rest works  */
  54.      "   }
  55.    for (i = 0; i < 5; ++i)  {
  56.     printf("%s%s",secret[i].full_name, "   ");
  57.     printf("%d%s%5.2f\n", secret[i].age,"    ",secret[i].salary);
  58.     }
  59.   return 0;
  60. }
  61.  
  62.  I've stated the trouble some part above.  What I want to do is this:
  63.  
  64.  The computer randomly picks a first name, let's say: Michael
  65.  Then the computer picks a last name:  Jordan
  66.  These are two separate strings.  I want to pit these strings together 
  67.  to form: Michael Jordan.  
  68.  Then printed out.  Of course I have to do    more than 1 name.  My   
  69. orginal code is much longer(I am given 15 first  names and 20 last  
  70. names). I have to form 50 names from it. Can you fix my code?
  71.  Thanks in advance for the help.
  72.  
  73.   please e-mail me at spdcool@ix.netcom.com and spd7398@acf4.nyu.edu
  74.   mail me at both places b/c I may be at home or in school   
  75.      
  76.